import '../entities/user_entity.dart';

/// 用户过滤内容响应模型
/// 
/// 对应接口: GET /api/user/filtered-content/{userId}
/// 用于查看他人主页时获取的用户信息和内容
class UserFilteredContentResp {
  final String status;
  final UserEntity? user;
  final int? friendCount;
  final List<dynamic>? activities;  // 活动列表
  final List<dynamic>? comments;     // 评论列表
  final String? message;

  UserFilteredContentResp({
    required this.status,
    this.user,
    this.friendCount,
    this.activities,
    this.comments,
    this.message,
  });

  /// 从JSON创建实例
  factory UserFilteredContentResp.fromJson(Map<String, dynamic> json) {
    return UserFilteredContentResp(
      status: json['status']?.toString() ?? 'error',
      user: json['user'] != null 
          ? UserEntity.fromJson(json['user'] as Map<String, dynamic>)
          : null,
      friendCount: json['friend_count'] as int?,
      activities: json['activities'] as List<dynamic>?,
      comments: json['comments'] as List<dynamic>?,
      message: json['message']?.toString(),
    );
  }

  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'status': status,
      'user': user?.toJson(),
      'friend_count': friendCount,
      'activities': activities,
      'comments': comments,
      'message': message,
    };
  }

  /// 创建成功响应
  factory UserFilteredContentResp.success({
    required UserEntity user,
    int? friendCount,
    List<dynamic>? activities,
    List<dynamic>? comments,
  }) {
    return UserFilteredContentResp(
      status: 'success',
      user: user,
      friendCount: friendCount,
      activities: activities,
      comments: comments,
    );
  }

  /// 创建失败响应
  factory UserFilteredContentResp.failure(String message) {
    return UserFilteredContentResp(
      status: 'error',
      message: message,
    );
  }

  /// 是否成功
  bool get isSuccess => status == 'success';

  @override
  String toString() {
    return 'UserFilteredContentResp(status: $status, user: ${user?.username}, friendCount: $friendCount, activitiesCount: ${activities?.length}, commentsCount: ${comments?.length})';
  }
}

